package com.bw.liuyushan.zhuangao4_mvptest1.MVP.View.Activity;

import android.animation.Animator;
import android.animation.ObjectAnimator;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bw.liuyushan.mvp_lib.View.BaseActivity;
import com.bw.liuyushan.zhuangao4_mvptest1.Entity.JsonBean;
import com.bw.liuyushan.zhuangao4_mvptest1.MVP.Contrack.ICTest;
import com.bw.liuyushan.zhuangao4_mvptest1.MVP.Model.BaseModelTest;
import com.bw.liuyushan.zhuangao4_mvptest1.MVP.Presenter.BasePresenterTest;
import com.bw.liuyushan.zhuangao4_mvptest1.R;

import java.io.Serializable;

/**
 * ZhuanGao4_MVPTest1
 * file name is : FoodItemActivity
 * created by Ender on 2021/8/18 14:09.
 * author : Liuyushan
 * Describe(作用):TabFragment大虾串点击跳转的详情Activity 接收值 显示 属性动画
 */
public class FoodItemActivity extends BaseActivity<BasePresenterTest> implements ICTest.C_ViewTest{
        private android.widget.TextView tvsimFood;
        private android.widget.ImageView imgsimFood;
    private android.widget.TextView tvsim2Food;

    @Override
    public int bindLayout() {
        return R.layout.activity_fooditem;
    }

    @Override
    public void initView() {
        //防止内存泄露
        ip = new BasePresenterTest(new BaseModelTest(), this);

        tvsimFood = (TextView) findViewById(R.id.tvsim_Food);
        imgsimFood = (ImageView) findViewById(R.id.imgsim_Food);
        tvsim2Food = (TextView) findViewById(R.id.tvsim2_Food);
    }

    @Override
    public void initDate() {
        Intent intent = getIntent();
        JsonBean.DataBean objectF = (JsonBean.DataBean) intent.getSerializableExtra("objectF");
        Glide.with(getApplicationContext()).load(objectF.getPic()).circleCrop().into(imgsimFood);
        //属性动画 rotation旋转
        ObjectAnimator rotation = ObjectAnimator.ofFloat(imgsimFood, "rotation", 360, 0);
        rotation.setDuration(1000);//设置时间
        rotation.start();//开始动画
        //动画监听事件
        rotation.addListener(new Animator.AnimatorListener() {
            @Override
            public void onAnimationStart(Animator animation) {

            }

            @Override
            public void onAnimationEnd(Animator animation) {
                //动画完成时传值
                tvsimFood.setText(objectF.getTitle().toString());
                tvsim2Food.setText(objectF.getFood_str().toString());
            }

            @Override
            public void onAnimationCancel(Animator animation) {

            }

            @Override
            public void onAnimationRepeat(Animator animation) {

            }
        });

        //详情图片点击事件
        imgsimFood.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ObjectAnimator rotation = ObjectAnimator.ofFloat(imgsimFood, "rotation", 360, 0);
                rotation.setDuration(1000);//设置时间
                rotation.start();//开始动画
            }
        });
    }
}
